package com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.qingyiapp.R;
import com.example.qingyiapp.service.entify.FindChoicenessOneBean;
import com.example.qingyiapp.service.entify.FindChoicenessTwoBean;
import com.example.qingyiapp.service.entify.FindSynamicBean;
import com.example.qingyiapp.service.entify.FindTJBean;
import com.example.qingyiapp.service.entify.FindWaitYouBean;
import com.example.qingyiapp.service.presenter.PersenterMannaer;
import com.example.qingyiapp.service.view.IFindView;
import com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.utils.ChoicenessBean;
import com.example.qingyiapp.ui.activity.fragment.fragment_FindUI.utils.SpacesItemDecoration;

import java.util.ArrayList;
import java.util.List;

/**
 * Creadted by Met·Wang on 2019/9/19 15:07
 * Describe: NullPointerException Write
 */
public class ChoicenessAdapter extends RecyclerView.Adapter<ChoicenessAdapter.VHolder> implements IFindView {

    ArrayList<ChoicenessBean> list;
    Context context;


    ArrayList<FindChoicenessOneBean.DataBean> datas1;
    ArrayList<FindChoicenessTwoBean.DataBean> datas2;

    PersenterMannaer mannaer;
    FindChoicenessRecyclerAdapter adapter;
    FindChoicenessRecycler2Adapter adapter2;
    public ChoicenessAdapter(ArrayList<ChoicenessBean> list, Context context) {
        this.list = list;
        this.context = context;
        mannaer=new PersenterMannaer(context,"http://www.iqingyi.com/");
        mannaer.onCreate();
        mannaer.attchview2(this);
        mannaer.getFindChoicenessBean();
        mannaer.getFindChoicenessTwoBean();

        datas1=new ArrayList<>();
        datas2=new ArrayList<>();
    }

    @NonNull
    @Override
    public VHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.fragment_find_coiceness_xrecyclerview_item, null, false);

        return new VHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull final VHolder vHolder, int i) {
        vHolder.title.setText(list.get(i).getTitle()+"");
        vHolder.more.setText(list.get(i).getMore()+"");
        LinearLayoutManager manager=new LinearLayoutManager(context);

        vHolder.recyclerView.setLayoutManager(manager);
        int space = 10;
        vHolder.recyclerView.addItemDecoration(new SpacesItemDecoration(space));


        if(i==0){
            adapter2=new FindChoicenessRecycler2Adapter(datas1,context);
            vHolder.recyclerView.setAdapter(adapter2);


        }else {
            adapter=new FindChoicenessRecyclerAdapter(datas2,context);
            vHolder.recyclerView.setAdapter(adapter);

        }








    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void getjsonstring(FindTJBean s) {

    }

    @Override
    public void getChoicenessOneBean(FindChoicenessOneBean bean) {

        List<FindChoicenessOneBean.DataBean> data = bean.getData();
        for (int i = 0; i < data.size(); i++) {
            datas1.add(data.get(i));
        }
        adapter2.notifyDataSetChanged();

    }

    @Override
    public void getChoicenessTwoBean(FindChoicenessTwoBean bean) {
        List<FindChoicenessTwoBean.DataBean> data = bean.getData();
        for (int i = 0; i < data.size(); i++) {
            datas2.add(data.get(i));
        }
        adapter.notifyDataSetChanged();
    }

    @Override
    public void getFindWaitYou(FindWaitYouBean bean) {

    }

    @Override
    public void getFindSynamic(FindSynamicBean bean) {

    }


    class VHolder extends RecyclerView.ViewHolder{
        TextView title;
        TextView more;
        RecyclerView recyclerView;

        public VHolder(@NonNull View itemView) {
            super(itemView);
            title= itemView.findViewById(R.id.item_myText);
            more= itemView.findViewById(R.id.item_myText2);
            recyclerView= itemView.findViewById(R.id.choiceness_xrecyler_item_xrecycler);

        }
    }
}
